package ce.com.cenewbluesdk.entity.k3;


import java.io.Serializable;

import ce.com.cenewbluesdk.CEBC;
import ce.com.cenewbluesdk.entity.BaseData;
import ce.com.cenewbluesdk.entity.CEDevData;
import ce.com.cenewbluesdk.uitl.ByteUtil;
import ce.com.cenewbluesdk.uitl.CRC16;

/**
 * Created by Administrator on 2016/2/25 0025.
 */
public class Send_User_Card extends BaseData implements Serializable {

    public static final int sendDateSize = 2051;

    private int crc;
    private int type;
    private byte[] data;

    private byte[] sendData;

    public Send_User_Card(int type, byte[] data) {
        this.type = type;
        this.data = data;
        sendData = new byte[sendDateSize];
        sendData[2] = (byte) type;
        System.arraycopy(data, 0, sendData, 3, data.length);
        int crc = CRC16.crc16(sendData, 2);
        byte[] bytes = ByteUtil.int2bytes2(crc);
        sendData[0] = bytes[0];
        sendData[1] = bytes[1];
    }

    public int getCrc() {
        return crc;
    }

    public int getType() {
        return type;
    }

    public byte[] getSendData() {

        return sendData;
    }

    @Override
    public CEDevData toCEDevData() {
        CEDevData data = new CEDevData(CEBC.CMD_SEND_TYPE, CEBC.K3.DATA_TYPE_USER_CARD);
        data.setItemL(sendDateSize);
        data.setItemNumber(1);
        data.setData(getSendData());
        byte[] argv = new byte[12];
        argv[0] = (byte) getType();
        argv[1] = (byte) (sendDateSize % 256);
        argv[2] = (byte) (sendDateSize / 256);
        data.setOtherData(argv);
        return data;
    }
//    private byte[] getSendData(int index) {
//        int len;
//        if(index+ TransBlock.MAX_BLOCK_PAYLOAD_SIZE>sendDateSize){
//            len =sendDateSize-index;
//        }else {
//            len=TransBlock.MAX_BLOCK_PAYLOAD_SIZE;
//        }
//        byte da[]=new byte[len];
//        System.arraycopy(sendData,index,da,0,len);
//        return da;
//    }
}
